The C++ language is engaged in a long and exacting standardization process. This process has been jointly supported by the International Standards Organization (ISO) and the American National Standards Institute (ANSI). Rogue Wave representatives have attended every standardization committee meeting since 1993. It is the only company on the committee engaged exclusively in the business of the development of class libraries. Rogue Wave has presented numerous proposals that have been accepted as part of the standard. Many of these have drawn on the company's vast experience in providing C++ class libraries to the marketplace for both Unix and PC platforms.
A major part of the specification that has been developed is the Standard C++ Library. While ANSI and ISO approve standards for the C++ language, they do not write code. Rogue Wave has implemented the standards specified by ANSI and ISO, and created a thoroughly tested, robust, and conforming implementation of the Standard C++ Library. Rogue Wave then adapted Tools.h++so that it offers an effective object-oriented interface to the Standard C++ Library. From the marriage of these two products, C++ developers gain the power and flexibility of the standard with the advantages of object-orientation.
This technical report provides information on the structure of the Standard C++ Library, and describes how Tools.h++ provides an object-oriented interface to that library. Further, it provides insight into future versions of Rogue Wave products, and how they will work with the Standard C++ Library.
A major result of the ANSI/ISO standardization of the C++ programming language is the Standard C++ Library, a large and comprehensive collection of classes and functions. Both the ANSI/ISO Standard C++ Library and Rogue Wave's implementation include the following parts:
A major portion of the ANSI/ISO Standard C++ Library is comprised of a collection of class definitions for standard data structures and a collection of algorithms commonly used to manipulate such structures. This part of the library was originally known as the STL. The organization and design of the STL differs in almost all respects from the design of most other C++ libraries because it avoids encapsulation and uses almost no inheritance.
An emphasis on encapsulation is a hallmark of most object-oriented programming. The concept of combining data and functionality into an object is a powerful organizational principle in software development; indeed it is the primary organizational principle. Through the proper use of encapsulation, even exceedingly complex software systems can be divided into manageable units and assigned to various members of a development team.
Inheritance is a powerful technique for permitting code sharing and software reuse, especially when two or more classes share a common set of basic features. For example, two types of windows in a graphical user interface may inherit from a common base window class, with the individual subclasses providing any required unique features. Similarly, object-oriented container classes may ensure common behavior and support code reuse by inheriting from a more general class, and factoring out common member functions.
The templates in the Standard C++ Library are based on the STL. They are class declarations parameterized on types, and prescriptions for how particular types of collections should behave. The key to templates is that the data structures are separated from the algorithms. The designers of the STL purposely separated the tasks to be performed using common data structures from the representation of the structures themselves. This is why the Standard C++ Library is properly viewed as a collection of algorithms and, separate from these, a collection of data structures that can be manipulated using the algorithms. The algorithms are written generically, without regard for the data structures upon which they will operate. This feature allows developers to add data structures that can immediately leverage existing algorithms. Conversely, developers can add new algorithms that will work with any existing data structure.
Of course, different data structures have different time/space characteristics. Thus, for templates to work, the time/space characteristics of both data structures and algorithms must be recorded and standardized. The Standard C++ Library records and standardizes this information, allowing data structures and algorithms to be combined in many different ways with highly predictable results. However, the resulting power and flexibility come at the cost of increased complexity and diminished protection against programming errors.
The non-object-oriented design of the Standard C++ Library produces a number of side effects, some advantageous and some not, that developers must be aware of as they investigate how to most effectively use the library.
Among the advantages of the non-object-oriented design of the Standard C++ Library are:
Among the disadvantages of the non-object-oriented design of the Standard C++ Library are:
Tools.h++ simplifies the C++ language, and provides multithread-safe protection and easy migration paths to multithreaded and distributed environments. The essential feature of Tools.h++ is that it encapsulates the non-object-oriented Standard C++ Library with a familiar object-oriented interface. Developers access the power of the Standard C++ Library and the advantages of object-orientation. In addition, Tools.h++ includes a host of other valuable features that are not included in the ANSI/ISO Standard C++ Library, such as time, date, regular expression, Small Talk-like collections, and hash tables.
Here is how the process works. The Tools.h++ collection classes themselves are not ANSI standard classes. Instead, each collection offers a member function std(), which returns a reference to the ANSI standard implementation of that collection. This neatly separates the Tools.h++ interface from the Standard C++ Library interface, while still accessing the benefits and features of the standard.
The Standard C++ Library is a powerful, effective, and efficient engine to put under the hood of the Tools.h++ template collections. Tools.h++ template collection classes are built by wrapping Standard C++ Library template collections with a Rogue Wave interface. In other words, each Tools.h++ collection has a has-a relationship with a corresponding Standard C++ Library collection that serves as the implementation for the collection. A Tools.h++ collection has no state other than the state of the Standard C++ Library implementation that it conforms to. This allows a Tools.h++ collection to provide direct access to the implementation without any loss of integrity.
For example, the value-based Tools.h++ double-ended queue, RWDequeVal<T>, has-a member of type deque<T> from the Standard C++ Library. This member serves as the implementation of the queue, doing the bulk of the work of adding and removing elements, etc. The wrapper class mitigates the disadvantages of using the deque class directly by offering a simpler, object-oriented interface. Thanks to inlining and the lack of any extra level of indirection, this wrapping incurs few, if any, performance penalties. For the intrepid developer needing access to the implementation directly, the wrapper classes offer the member function std(), which returns a reference to the implementation. In addition, because the Tools.h++ template collections supply standard iterators, they can be used with the standard algorithms as if they were Standard C++ Library collections themselves.
Tools.h++offers one set of collection classes based on templates. This set is based on the Standard C++ Library and on the previous Tools.h++ collections. In almost all cases, developers will be able to use the implementation based on the Standard Library without changing their source code-provided the compiler supports the features necessary for the Standard C++ Library, and provided it is installed. If the compiler does not support them, or the developer does not have the Standard C++ Library installed, the collections not based on the Standard C++ Library will be used.
Division | Value-based | Pointer-based |
Sequence-based (External ordering, access by index) | ||
RWDlistVal
RWDequeVal RWOrderedVectorVal RWSlistVal | RWDlistPtr RWDequePtr RWOrderedVectorPtr RWSlistPtr | |
Sorted sequence-based (Internal ordering, access by index) | ||
RWSortedDlistVal
RWSortedVectorVal | RWSortedDlistPtr RWSortedVectorPtr | |
Associative container-based (Internal ordering, access by key) | ||
(set-based) | RWSetVal
RWMultiSetVal | RWSetPtr RWMultiSetPtr |
(map-based) | RWMapVal
RWMultiMapVal | RWMapPtr RWMultiMapPtr |
Associative hash-based (No ordering, access by key) | ||
(set-based) | RWHashSetVal
RWHashMutliSetVal | RWHashSetPtr RWHashMultiSetPtr |
(map-based) | RWHashMapVal
RWHashMultiMapVal | RWHashMapPtr RWHashMultiMapPtr |
Today's C++ developers face a range of problems. Thus, the C++ language supports a wide range of programming approaches to help developers solve this range of problems. The language, and now the Standard C++ Library that supports it, are designed to deliver the power to approach each unique problem from the best possible angle. The Standard C++ Library, when combined with more traditional object-oriented programming techniques, puts a very flexible tool into the hands of anyone building a collection of C++ classes, whether those classes are intended to stand alone as a library, or are tailored to a specific task.
Within a few years the Standard C++ Library will be the standard set of classes and libraries delivered with all ANSI-conforming C++ compilers. Most of these compilers will bundle Tools.h++ as well. As noted, the design of a large portion of the Standard C++ Library is not object-oriented. On the other hand, C++ excels as a language for manipulating objects. How does today's intrepid developer integrate the Standard C++ Library's non-object-oriented architecture with C++'s strengths as a language for manipulating objects?
Both Tools.h++ and the Standard C++ Library offer significant benefits to developers. Given the benefits of both, the key is to use the right tool for each task.
Standard C++ Library components should be used directly when flexibility and/or highly efficient code is required. The Standard C++ Library excels in the creation of reusable classes, where low-level constructs are needed. For example, the Standard C++ Library would be the correct choice for a developer who needs an especially efficient data structure or algorithm, such as data stream manipulation in drivers (the kind of problem that often resolves to a single class). However, developers who use the Standard C++ Library must be willing to invest the extra time necessary to keep potential problems from occurring.
For the most part, however, object-oriented design methods and programming techniques are almost without peer as guideposts in the development of large complex software. Object-oriented techniques really shine when low-level classes are combined to solve a larger problem. Thus, for the large majority of programming tasks, object-oriented techniques remain the preferred approach. Encapsulation and inheritance should always be considered to compartmentalize a problem, especially in modeling larger problem domains where the pieces must be knit into a full solution. Tools.h++ encapsulates the Standard C++ Library to provide its power and flexibility with a familiar object-oriented interface. It is even reasonable to suggest that most developers using Tools.h++ will never need to directly access the Standard C++ Library.
Developers, too, will be evolving their designs and implementations toward the emerging standard at various rates as appropriate to their development environment, application domain, and even corporate culture. Developers who use the template classes in Tools.h++ can maintain consistency in development projects while moving, at their own pace, along the path of the latest C++ technology.
Additionally, future versions will include a wide character regular expression class, a path class, graphic classes, and classes that enhance the Standard C++ Library locale facility.
Future developments at Rogue Wave will include a distributed version of Tools.h++ in which all classes will be available as distributed objects. This library will be based on the CORBA (Common Object Request Broker Architecture) standard. The product will allow users to leverage existing code while providing easy migration to distributed environments.
The ANSI/ISO Standard C++ Library offers tremendous potential to developers. To provide maximum power and flexibility to developers, it was purposely designed with an architecture that is not object-oriented. However, the price of this benefit is complexity and a potential for error.
Rogue Wave's Tools.h++ API provides a robust and proven object-oriented interface for the Standard C++ Library. This interface is less error prone and simpler to use. It provides added functionality, and a path for migrating to multithreaded and distributed environments. The combination will provide developers with both the portability of the standard, and the safety and reusability of an object-oriented language.